﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;

namespace Cesave.Infrastructure.Data.Core.Tests.StubAndMoles
{
    /// <summary>
    /// Context stub for test a GenericRepository base class
    /// </summary>
    public class ContextStub
        : Cesave.Infrastructure.Data.Core.Moles.SIQueryableContext
    {
        #region Members

        static List<Entity> entityList;

        #endregion

        #region Constructor

        /// <summary>
        /// Default constructor for this context stub.
        /// This constructor prepare stub with fake contents
        /// </summary>
        public ContextStub()
        {
            PrepareStub();
        }

        #endregion

        #region Private Methods

        private void PrepareStub()
        {
            //List prepare fake object set

            entityList = new List<Entity>()
            {
                new Entity(){Id=1,Field="field 1"},
                new Entity(){Id=2,Field="field 2"},
                new SubEntity(){Id=3,Field="field 3"}
            };

            InMemoryObjectSet<Entity> fakeObjectSet = entityList.ToInMemoryObjectSet();

            //Assign this object set when CreateObjectSet<Entity> is executed!
            this.CreateObjectSet<Entity>(() => fakeObjectSet as IObjectSet<Entity>);

            //prepare ApplyChanges stub 
            this.SetChangesTEntity<Entity>((item) =>
            {
            });
        }

        #endregion
    }
}
